package com.android.videotest.music.ui.playlist;

import android.support.v4.media.MediaBrowserCompat;
import android.support.v4.media.MediaDescriptionCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.android.videotest.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PlayListAdapter extends RecyclerView.Adapter<PlayListAdapter.PlayListHolder> {


    private List<MediaBrowserCompat.MediaItem> mChildren;

    @NonNull
    @Override
    public PlayListHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item_play_list, parent, false);
        return new PlayListHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PlayListHolder holder, int position) {
        MediaBrowserCompat.MediaItem item = mChildren.get(position);
        MediaDescriptionCompat description = item.getDescription();
        CharSequence title = description.getTitle();
        holder.tvTitle.setText(title);
        holder.ivDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }

    @Override
    public int getItemCount() {
        return mChildren == null ? 0 : mChildren.size();
    }

    public void setData(List<MediaBrowserCompat.MediaItem> children) {
        mChildren = children;
        notifyDataSetChanged();
    }

    static class PlayListHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_volume)
        ImageView ivVolume;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.iv_delete)
        ImageView ivDelete;
        public PlayListHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}

